var express = require('express');
var router = express.Router();
const url=require("url");
const querystring=require("querystring")
const MongoClient=require("mongodb").MongoClient;
const { ObjectID } = require('mongodb');
var dbName="blog"

/* 点赞爱心.更新当前的点赞数量*/


router.get('/', function(req, res, next) {
var _id=querystring.parse(url.parse(req.url).query).id

 MongoClient.connect("mongodb://localhost:27017",function(err,client){
  if(err){throw err}
  
  var db=client.db(dbName);
  const collection=db.collection("myMind");

  collection.find({"_id":new ObjectID(_id)}).toArray(function(err,data){
    if(err){throw err}
   // console.log(data)
    collection.updateOne({_id:new ObjectID(data[0]._id)},{$set:{count:data[0].count+1}})
    res.end();
  })
  
})
  
});

module.exports = router;
